/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PenghuniKamarReportPanel.java
 *
 * Created on Nov 20, 2014, 2:40:25 PM
 */
package com.ivanbiz.ui;

import com.ivanbiz.dao.HistoryPenghuniDAO;
import com.ivanbiz.dao.impl.HistoryPenghuniDAOImpl;
import com.ivanbiz.model.HistoryPenghuni;
import com.ivanbiz.service.ServiceHelper;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author IW20149X
 */
public class PenghuniKamarReportPanel extends javax.swing.JPanel {

    List<HistoryPenghuni> listPenghuni;

    /** Creates new form PenghuniKamarReportPanel */
    public PenghuniKamarReportPanel() {
        initComponents();
        refresh();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePenghuniKamar = new javax.swing.JTable();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Report Penghuni Kamar");

        tablePenghuniKamar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tablePenghuniKamar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablePenghuniKamar;
    // End of variables declaration//GEN-END:variables

    private void refresh() {
        try {
            HistoryPenghuniDAO historyPenghuniDAO = new HistoryPenghuniDAOImpl();
            listPenghuni = historyPenghuniDAO.getAll(HistoryPenghuni.class);
            updateTablePenghuniKamar();
        } catch (Exception ex) {
            Logger.getLogger(PenghuniKamarReportPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateTablePenghuniKamar() {
        String[] judul = {"No", "Identitas", "Nama", "Jenis Kelamin", "Telp/HP", "Alamat"};
        Object[][] isi = new Object[listPenghuni.size()][6];
        int x = 0;
        int no = 0;
        for (HistoryPenghuni historyPenghuni : listPenghuni) {
            no += 1;
            isi[x][0] = no;
            isi[x][1] = historyPenghuni.getIdIdentitas();
            isi[x][2] = historyPenghuni.getNama();
            isi[x][3] = historyPenghuni.getKelamin();
            isi[x][4] = historyPenghuni.getTelp();
            isi[x][5] = historyPenghuni.getAlamat();
            x++;
        }
        new ServiceHelper().setAutoRize(isi, judul, tablePenghuniKamar);
    }
}
